<?php
namespace catchAdmin\product\request;

use catchAdmin\product\model\Product;
use catcher\base\CatchRequest;

class ProductUpdateRequest extends CatchRequest
{
    protected function rules(): array
    {
        return [
            'id' => 'require',
            'goods_name' => [
                'require',
                function($value, $data) {
                    $exists = Product::where('goods_name', $value)
                        ->where('tenant_id', request()->user()->tenant_id)
                        ->where('id', '<>', $data['id'])
                        ->where('deleted_at', 0)
                        ->find();
                    return $exists ? '已存在相同商品名称（料号）' : true;
                }
            ],
        ];
    }

    protected function message()
    {
        return [
            'id.require' => 'ID不能为空',
            'goods_name.require' => "商品名称（料号）不能为空"
        ];
    }
} 